package main

import (
	"log"

	handlers "iot/handler"
	"iot/mqttmodule"
	"iot/sql_models"

	"github.com/gin-gonic/gin"
)

func main() {

	client, err := mqttmodule.InitializeTLS("localhost", 8883, "HonokaLaptop", "honoka", "as123456")
	_ = client
	if err != nil {
		log.Fatalf("MQTT 初始化失败: %v", err)
	}
	handlers.InitMQTTModule()

	sql_models.PGSQL_init()
	
	// 创建 Gin 引擎
	r := gin.Default()

	// 注册路由
	r.POST("/mqtt-hook/publish", handlers.PublishHandler)
	r.POST("/mqtt-hook/connect", handlers.ConnectHandler)
	r.POST("/mqtt-hook/disconnect", handlers.DisconnectHandler)
	r.POST("/mqtt-hook/subscribe", handlers.SubscribeHandler)
	r.POST("/mqtt-hook/unsubscribe", handlers.UnsubscribeHanlder)

	// 启动服务器，监听7777端口
	r.Run(":7777")
}
